using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

using KNCApp.Util;
using KNCApp.Business.Models;
using KNCApp.Business.Interfaces;

namespace KNCApp.Business
{
    class PressureParser: Interfaces.IDataParser
    {
        ///private const string PRE_EXPR = @"^DM(1|2):[a-zA-Z]{1,}:\-?\d{1}\.\d{2}E(\+|\-){1}\d{2}:T\d{2}$";
        private string PRE_EXPR = Business.SettingsMgr.GetPressureFormat();
        private char[] PRE_SEPS = new char[] { ':' };

        private Regex preRE;
        
        public PressureParser()
        {
            preRE = new Regex(PRE_EXPR);
        }

        public AbstractObj Parse(string str)
        {
            str = str.Trim();
            Program.LogDebug("Pressure Parse - " + str);
            Pressure p = new Pressure();
            str = str.Replace(" ", "");
            string[] tokens = null;
            if (preRE.IsMatch(str))
            {
                Program.LogDebug("Pressure Data matched - " + str);
                tokens = str.Split(PRE_SEPS);
                if (tokens.Length > 2)
                {
                    p.Value = CmnTools.ConvertToDecimal(tokens[2]);
                    p.Unit = tokens[1];
                }
            }
            Program.LogDebug("Pressure Parse end ");
            return p;

        }
        public string GetMode()
        {
            return "";
        }
    }
}
